<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="com.store.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
User just_user = (User)session.getAttribute("LoginUser");
String power_enable_id =  "10102";//浏览（全部）
String power1_enable_id = "10108";//浏览（全部）
String power2_enable_id=  "10109";//分配工程师
String power3_enable_id = "10110";//定制工单
String power4_enable_id = "10103";//修改合同（本人）
String power5_enable_id = "10107";//修改合同（全部）
if (!just_user.hasPower(power_enable_id)&& !just_user.hasPower(power1_enable_id)) {
	out.println(strNoPowerInfo); 
	return;
}

String edate = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
Calendar calen = Calendar.getInstance();
calen.setTime(TSSDate.parseDate(edate));
calen.add(Calendar.MONTH, -1);
String bdate = new SimpleDateFormat("yyyy-MM-dd").format(calen.getTime());
ContractMgr contractMgr = new ContractMgr();
TechconengMgr techMgr = new TechconengMgr();
  UserMgr userMgr = new UserMgr();
 
List list = null;
List userList=null;
String area_id       = ParamUtils.getParameter(request,"area_id","");
int status     = ParamUtils.getIntParameter(request,"status",0);
int comid     = ParamUtils.getIntParameter(request,"comid",0);
String conid   = ParamUtils.getParameter(request,"conid","");
String service_id    = ParamUtils.getParameter(request,"serviceid","");
String customer = ParamUtils.getParameter(request,"customer","");
String saleid      = ParamUtils.getParameter(request,"saleid","");
String begin_date    = ParamUtils.getParameter(request,"begin_date",bdate);
String end_date      = ParamUtils.getParameter(request,"end_date",edate);
String techmanager    = ParamUtils.getParameter(request,"techmanager","");
String engineerid    = ParamUtils.getParameter(request,"engineerid","");
String prjname    = ParamUtils.getParameter(request,"prjname","");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'techcontract_list.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
   <link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function clk_contract_show(id) {
	right_menu_clk("outcon_show.jsp?conid="+ id);
}

function clk_choice_engineer(id) {
	right_menu_clk("../task_mgt/choose_engineer.jsp?conid="+ id+"&contype=2");
}

function clk_add_task(id,prjname,linkman,phone) {
	right_menu_clk("../task_mgt/task_add.jsp?conid="+ id+"&cusname="+ prjname+"&linkman="+ linkman+"&phone="+ phone+"&contype=2");
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="99%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
	 <td >
		<form name="pageForm" method="post">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td height="100" valign="top" align="center" style="padding-top:12px;padding-bottom:10px;">
								
					<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
					<tr bgcolor="#D7D7DB">
						<td height="25" style="padding-left:10px;">
						
						
					所在区域：
                  <select name="area_id"  style="width:60px" onchange="pageForm.submit();">
                   <option value="">全部</option>
                    <%for(int i=0;i<area_item_info.length;i++){%>
                    <option value="<%=area_item_info[i]%>"<%if (area_id.trim().equals(area_item_info[i])){%> selected<%}%>><%=area_item_info[i]%></option>
                    <%}%>
                  </select>
                  <%if(just_user.getRoleId().trim().equals(pa_role_id)||just_user.getRoleId().trim().equals(tm_role_id)){%>
                    项目经理：
            	      <select name="techmanager"  style="width:60px">
            	        <option value="">全部</option>
            	        <%
            	      
            	        String pm="pm";
            	         userList = userMgr.getUsersGroupbyroleid(pm);
            	        if (userList != null && userList.size() > 0) {
                    		for(int i=0;i<userList.size();i++){
                    			User item = (User)userList.get(i);
                    	%>
                        <option value="<%=item.getId()%>"<%if (item.getId().trim().equals(techmanager)) {%> selected<%}%>><%=item.getUserName()%></option>
                    	<%}}%>
            	      </select>
                	<%}%>
                	  
				     销售员：
            	      <select name="saleid"  style="width:60px">
            	        <option value="">全部</option>
            	        <%
            	      
            	        String saler="saler";
            	         userList = userMgr.getUsersGroupbyroleid(saler);
            	        if (userList != null && userList.size() > 0) {
                    		for(int i=0;i<userList.size();i++){
                    			User item = (User)userList.get(i);
                    	%>
                        <option value="<%=item.getId()%>"<%if (item.getId().trim().equals(saleid)) {%> selected<%}%>><%=item.getUserName()%></option>
                    	<%}}%>
            	      </select>
            	      登记日期：
              
                  从 <span id="htmlBeginTime">&nbsp;</span> &nbsp; 至 &nbsp; <span id="htmlEndTime" >&nbsp;</span>
					
				
						</td>
			<td align="center" width="7%">	
						<input type="submit" class="inputButton" value="确定">
						
            	      </td>
				  </tr>
		
					 <tr bgcolor="#FFFFFF">
					<td height="15" style="padding-left:10px;" colspan="4">
					</td>
					</tr>
				</table>

				<table width="100%" border="0" cellpadding="0" cellspacing="1"
					bgcolor="#FFFFFF">
					<tr align="center" bgcolor="#858585">
					<td width="13%"><font color="#FFFFFF">项目名称</font></td>
						<td width="10%" height="24"><font color="#FFFFFF">登记日期</font></td>
							
						<td width="6%"><font color="#FFFFFF">联系人</font></td>
						
						<td width="8%"><font color="#FFFFFF">项目经理</font></td>
						
						<td width="8%"><font color="#FFFFFF">厂商名称</font></td>
						<td width="8%"><font color="#FFFFFF">备件成本</font></td>
						
						<td width="8%"><font color="#FFFFFF">操作</font></td>
						
					</tr>
					<%
				 String otherSQL = "";
				 
				 if(just_user.hasPower(power1_enable_id)){
				 
				  otherSQL="and contype=2 ";
				 
				 }else if(just_user.hasPower(power_enable_id)){
				 
					  if(just_user.getRoleId().trim().equals(pm_role_id)){
					 
				          otherSQL="and contype=2 and techmanager='"+just_user.getId().trim()+"'";
				          
				      } else if(just_user.getRoleId().trim().equals(engineer_role_id)){
				      
				             otherSQL="and contype=2 and t.conid in (select conid from techconeng where taskid=0 and engid='"+just_user.getId()+"')";
				       }else if (just_user.getRoleId().trim().equals(pa_role_id)) {
				          		otherSQL=" and contype=2 and t.createman='"+just_user.getId()+"'";
				        }else  otherSQL=" and contype=2 and t.createman='"+just_user.getId()+"'";
				  }
				 	  if (comid !=0) otherSQL += " and t.comid = '" + comid+ "'";
				 	  if (! techmanager.trim().equals("")) otherSQL += " and t.techmanager = '" + techmanager+ "'";
				 	  if (! engineerid.trim().equals("")) otherSQL += " and t.engineer = '" + engineerid+ "'";
					  if (!area_id.trim().equals("")) otherSQL += " and t.area = '" + area_id.trim() + "'";
					  if (!service_id.trim().equals("")) otherSQL += " and t.serviceid like '%" + service_id.trim() + "%'";
					  if (!prjname.trim().equals("")) otherSQL += " and t.prjname like '%" + prjname.trim() + "%'";
					  if (!saleid.trim().equals("")) otherSQL += " and t.saleid = '" + saleid + "'";
					  if (!begin_date.trim().equals("")) otherSQL += " and substring(t.createtime for 10) >= '" + begin_date.trim() + "'";
					  if (!end_date.trim().equals("")) otherSQL += " and substring(t.createtime for 10) <= '" + end_date.trim() + "'";
              String orderField = "t.conid desc";
             int pageSize = 10;
			int pageno = 1;
			String page2 = request.getParameter("mgh");

			if (page2 == null || page2 == "") {
				pageno = 1;
			} else {
				pageno = Integer.parseInt(page2);
			}

			int pageNo = ParamUtils.getIntParameter(request, "page", pageno);
			String pageno1 = String.valueOf(pageNo);
			session.setAttribute("pageno", pageno1);
              list = contractMgr.get(otherSQL,orderField,pageNo,pageSize);
              int total = contractMgr.getTotal(); 
              boolean b=(total % pageSize ==0);
              int pageCount=b?(total/pageSize):(total/pageSize +1);
              if(pageNo>pageCount){
              	pageNo=pageCount;
              }
              if (list != null && list.size() > 0) {
              	String bgColor[] = {"#EDEDF0","#D7D7DB"};
              	for(int i=0;i<list.size();i++) {
              		Contract item = (Contract)list.get(i);
              		Calendar cal = Calendar.getInstance();
              		cal.setTime(item.getSevenddate());
              		cal.add(Calendar.DAY_OF_MONTH,-10);
              		String imgAlert = "";
              		if (cal.getTimeInMillis() < System.currentTimeMillis())
              			imgAlert = " <img src=\"images/contract_alert.gif\">";
              %>
					<tr align="center" bgcolor="<%=bgColor[i%2]%>" onMouseOver="this.style.background='#efefef'" onMouseOut="this.style.background='<%=bgColor[i%2]%>'">
						<td height="24"><a
							href="incontract_mgt/incon_detail.jsp?conid=<%=item.getId()%>"><%=item.getPrjname()%></a>
						</td>
					
							<td><%=item.getCreatetime()  + imgAlert%></td>
							
						<td><%=item.getLinkman()%></td>
							<%if( !item.getTechmanager().trim().equals("")){%>
						<td><%=item.getTechmanager_name()%></td>
						<%}else {%>
							<td>未分配</td>
							<%}%>
							
					
						<td><%=item.getCom_name()%></td>
						<td align="right"><%=FormatNum.formatCurrencycn(item.getSpartfee())%></td>
						<td>
						<%if (just_user.hasPower(power4_enable_id)||just_user.hasPower(power5_enable_id)){%>
						<span onclick="clk_contract_show('<%=item.getId()%>');"
							style="cursor:hand;text-decoration: underline;">修改</span>
							<%}%>
							<%if (just_user.hasPower(power2_enable_id)){
							String id="分配工程师";
							if(techMgr.hasTechcon(item.getConid())) id="重新分配";
							%>
					<span onclick="clk_choice_engineer('<%=item.getId()%>');"
							style="cursor:hand;text-decoration: underline;"><%=id%></span>
							<%}%>
							<%if (just_user.hasPower(power3_enable_id)){%>	
					<span onclick="clk_add_task('<%=item.getId()%>','<%=item.getPrjname()%>','<%=item.getLinkman()%>','<%=item.getPhone()%>');"
							style="cursor:hand;text-decoration: underline;">定制工单</span>
							<%}%>
							</td>
					</tr>
					<%}%>
				</table>
				<table width="99%" border="0" cellpadding="0" cellspacing="0" background="images/page_img/page_bk.gif">

										<tr height="32" align="center" valign="bottom">
											<td width="5%">
												<img src="images/page_img/page_tag_01.gif">
											</td>
											<td height="35" align="right" style="padding-right:10px;" valign="bottom" id="pannelPageInfo">
												&nbsp;
											</td>
										</tr>
									</table>
									<script language="javascript">
            							pannelPageInfo.innerHTML = getPageInfo(<%=total%>,<%=pageSize%>,<%=pageNo%>,5,'images/page_img','pageForm');
            						</script>
									<%} else {%>
					
								<table width="85%" border="0" cellpadding="4" cellspacing="1" bgcolor="#FFFFFF">
									<tr>
										<td height="60" align="center">
											请选择条件查询项目信息!
										</td>
									</tr>
								</table>
								<%}%>
							</td>
						</tr>

				</table>
					</form>
				</td>
			</tr>
		</table>
	<script language="javascript">
	htmlBeginTime.innerHTML = showCalenderInput("begin_date","pageForm","<%=begin_date%>",1);
	htmlEndTime.innerHTML = showCalenderInput("end_date","pageForm","<%=end_date%>",1);
</script>
	</body>
</html>
